<?php
require_once("config.inc.php");
require_once("weibo.class.php");
require_once("wnl.class.php");
require_once("db.class.php");

header( "Content-Type:text/html; charset=utf-8" );
//header( "Content-type: image/png" );
$wb = new weibo(APP_KEY, SECRET_KEY);
$wb->setUser( USER_NAME , USER_PASS );
$db = new db($site_Db);

$handle = new wnl(&$wb,&$db,'',$option_form[$type]);
if($handle->run()) {
	$text = $handle->get_Response_data();
	$day_array = $handle->get_Response_day();
	$month_array = $handle->get_Response_month();
	$current_dir = dirname(__FILE__) . '/';
	
	if ( !( $im = @imagecreatefrompng($current_dir.'back.png') ) )
	{
		exit( "Cannot Initialize new GD image stream." );
	}
	
	$black = imagecolorallocate($im, 0, 0, 0);
	$red = imagecolorallocate($im, 255, 0, 0);

	imagettftext($im, 20, 0, 25, 30, $red, $current_dir."simhei.ttf", "{$day_array['year']}年{$day_array['month']}月{$day_array['day']}日");
	imagettftext($im, 14, 0, 215, 30, $black, $current_dir."simhei.ttf", "农历 {$month_array['mnl']} 生肖 {$month_array['msx']}");
	
	$font_size = 16;
	$font = $current_dir."SIMLI.TTF";
	$start_x = 25;
	$start_y = 60;
	$step_y = 30;
	
	imagettftext($im, $font_size, 0, $start_x, $start_y, $black, $font, '公  历：');
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y, $black, $font, '农  历：');
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*2, $black, $font, '节  日：');
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*3, $black, $font, '节  气：');
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*4, $black, $font, '干  支：');
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*5, $black, $font, '二十八宿：');
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*6, $black, $font, '甲子纳音：');
	
	$font_size = 14;
	$font = $current_dir."simsun.ttc";
	$start_x = 135;
	$start_y = 61;
	$step_y = 30;
	imagettftext($im, $font_size, 0, $start_x, $start_y, $black, $font, "{$day_array['year']}年{$day_array['month']}月{$day_array['day']}日 {$day_array['xingqi']} {$day_array['xingzuo']}");
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y, $black, $font, "{$day_array['nongli']}");
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*2, $black, $font, "{$day_array['jieri']}");
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*3, $black, $font, "{$day_array['jieqi']}");
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*4, $black, $font, "{$day_array['ganzhi']}");
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*5, $black, $font, "{$day_array['ershibasu']}");
	imagettftext($im, $font_size, 0, $start_x, $start_y + $step_y*6, $black, $font, "{$day_array['jiazinayin']}");
	
	ob_start();
	imagepng( $im );
	$result=ob_get_contents();
	ob_end_clean();
	//echo $result;
	imagedestroy( $im );
	
	$wb->upload("今日万年历   ".$text, $result);
	//$wb->update("今日万年历   ".$today);
	echo "update success!";
}

?>